package com.demo.cloud.autoconfig.starter.config;

import com.demo.cloud.autoconfig.starter.properties.LuckyNumProperties;
import com.demo.cloud.autoconfig.starter.service.LuckyNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnWebApplication //web应用生效
@EnableConfigurationProperties(LuckyNumProperties.class)//使属性文件类生效
public class LuckyNumAutoConfiguration {
    @Autowired
    LuckyNumProperties luckyNum;

    @Bean
    public LuckyNumberService luckyNumberService(){
        LuckyNumberService luckyNumberService = new LuckyNumberService();
        luckyNumberService.setLuckyNum(luckyNum);
        return luckyNumberService;
    }
}
